//Includes
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
/* //Who the fuck keeps using java commands? //an enterprise-grade(R) programmer
import javax.servlet;
import javax.servlet.*;
import java.util.*;
import java.io.*;
*/

//Defines
#define len(x) (sizeof(x) / sizeof(*(x)))
#define DEBUG 1

/* Rules and guidelines
 * 
 * Copy to clipboard often
 * Comment out WIP code until it's finished
 * Don't put braces on a new line unless you suck cock
*/

/* Chat
Fug DDD:
How do we fix the segfault goys?
Git Gud
*/

//Function stereotypes go here
int main(void);
void printLogo(void);

void little_meme(void);
void shitLord(int to);
void the_end_of_time(void);
void linked_list(unsigned int j);
void current_time(void);
void benis_print(void);
int check_benis_lenght(void);

void sort_shit(void);
void print_array(int* input, int size);
void merge_sort(int* array, size_t size);
int* copy_arr(int* data, size_t size, int* dest);
void cuck_sort(int* data, size_t size);

//Typedefs / structs

//Body
int main(void) {
  //printLogo();
  //current_time();
  //check_benis_lenght();
  sort_shit();
  //little_meme(); //keep this uncommented
  //benis_print();
  //check_benis_lenght();
  //printf("benis amiright? ::DDDDDD\nAm I cool yet? :::333333333333333333");
  return EXIT_SUCCESS;
}

void benis_print() { /*//warning, declaration shit. Why didn't you just let me nigga
  int kkk = 0;
  do { 
    printf("benis!\n");
    wait(0.1);
    kkk = kkk + 1;
  }while ( kkk < 6 );*/
}

void printLogo() {
    puts(
        "                             Welcome to the                             \n"
        "             ___       _         ___            _         __            \n"
        "            / _ \\     | |       / / |          | |       / /            \n"
        "           | (_) | ___| |__    / /| |_ ___  ___| |__    / /             \n"
        "            > _ < / __| '_ \\  / / | __/ _ \\/ __| '_ \\  / /              \n"
        "           | (_) | (__| | | |/ /  | ||  __/ (__| | | |/ /               \n"
        "            \\___/ \\___|_| |_/_/    \\__\\___|\\___|_| |_/_/                \n"
        "                         _                                              \n"
        "                        /  _  _| _ ._._  _. _|                          \n"
        "                        \\_(_)(_|(/_| |_)(_|(_|                          \n"
        "                                     |                                  \n"
        "                _____ _     _ _       _                                 \n"
        "               / ____| |   (_) |     | |                                \n"
        "              | (___ | |__  _| |_ ___| |__   _____      __              \n"
        "               \\___ \\| '_ \\| | __/ __| '_ \\ / _ \\ \\ /\\ / /              \n"
        "               ____) | | | | | |_\\__ \\ | | | (_) \\ V  V /               \n"
        "              |_____/|_| |_|_|\\__|___/_| |_|\\___/ \\_/\\_/                \n"
        "                                                                        \n"
        "                      Sponsored by Terry A. Davis,                      \n"
        "                  Intel-Aviv Women's Outreach Program,                  \n"
        "                         Bernadette Masciocchi,                         \n"
        "                              and ReiserFS                              \n"
    );
}

void sort_shit(void) {
  int sortTest[] = {20,50,10,5,30,80,90,100,50}; //OK, so it's at least stable //yay!
  
  /*for (int i = 0; i < len(sortTest); i++) {
    sortTest[i] = abs(rand()) / 1e5;
  }*/
  
  //printf("Can tech write a sort? Let's find out\n");
  printf("Before: ");  print_array(sortTest, len(sortTest)); putchar('\n');
  cuck_sort(sortTest, 8);
  printf("After:  ");  print_array(sortTest, len(sortTest)); putchar('\n');
}

void print_array(int* input, int size) { //KEK @ the definition of this shit1!!! what are we doing?!!
  int i;
  
  putchar('[');
  for (i = 0; i < size; i++) {
    printf("% 3d" , i[input]);
    if (i < size-1) printf(", ");
    // >i[input] - absolutely haram! 4 u
    //what does this code do //before I corrected it, it just printed i!!!!!! Someone messed it up somehow, before it worked flawlessly.i wish i can write C who made the ascii? //Me, the guy that writes in camelcase
  }
  putchar(']');
}

void merge_sort(int* array, size_t size) {
    int i, j;
    int temp;
    
  for (i = 0; i <= size; i++) {
    for (j = 1; j <= (size-i); j++) {
      if(array[j-1] > array[j]) {
      temp = array[j];
      array[j] = array[j-1];
      array[j-1] = temp;
      }       
    }
  }
}

int* copy_arr(int* data, size_t size, int* dest) {
  if (DEBUG) {
    printf("\x1b[33m" "copy_arr" "\x1b[0m" "(\n  data="); print_array(data, size);
    printf(",\n  size=%d [%d]\n)\n", (int) size, (int) len(data));
  }
  
  if ((dest)==NULL) {
    dest = malloc(size * sizeof(int));
  }

  for (size_t i = 0; i < size; i++)
    dest[i]=data[i];

  return dest;
}
//thanks if you get this shit sorted wanna see something cool?DanielfromSL oh my bad //sure //i thought you meant on here ;-;
void mem_swap(int* data, int h) {
  if (DEBUG) printf("\x1b[32m" "mem_swap" "\x1b[0m" "(data=[%d, %d])\n", *data, *(data + 1));
  
  //I would kill for a repl
  //It's not swapping, and it's getting the pointer inserted into it //wait what the fuck
  //? It's using the pointers to swap. 
  //I see. It's sorting, mem_swap's debug output is just weird
  /*int* temp = malloc(2*h*sizeof(int)); //this works for the backwards case! It's just some memory fuckery left
  int l=0;
  int j=h;
  int i=0;
  while (i < h){
    for(j=h;j<2*h;){
      if(data[j]<data[i]) {
        temp[l]=data[j];
        j++;
      } else {
        temp[l]=data[i];
      }
    }
  }
  
  for (int i=h;i<2*h;i++)
    data[i-h]=data[i];
  
  for (int i=0;i<h;i++)
    data[h+i]=temp[i];*/
 //I am bad at pointers
  
  /*int temp;
  temp = *(data + 1);
  data = temp;*/
  
 if (DEBUG) printf("\x1b[31m" "mem_swapa" "\x1b[0m" "(data=[%d, %d])\n", *data, *(data + 1));
}

void cuck_sort(int* data, size_t size) { // wait a second! I think cuck-sort is fucking pointless. It's not a real sorting algorithm, we would need to do something else, since if two of the adjacent values in the sorted array are not naighbors in the original, this won't pair them up, ever! FUCK! Or maybe it will and we just fucked up the implementation. I dunnp. 
  
  //OK, we need to compare each element in the sub-arrays when merging, not just swapping the two.
  
  //Above is what need to be done, but I can't be bothered. bye! //have a good one
  //Good thing I'm NEET. Hate to waste useful time.
    assert(size >= 2);
    
    if (DEBUG) {
       printf("\x1b[34m" "cuck_sort" "\x1b[0m" "(\n  data="); print_array(data, size);
       printf(",\n  size=%d [%d]\n)\n", (int) size, (int) len(data)); //so len is fukd?
    }

    if (size > 2) {
        int h = size / 2;
        if (DEBUG) printf("cucksort: size > 2, splitting size=%d to h=%d\n", (int) size, h);
        cuck_sort(data, h);
        cuck_sort(&data[h], (size - h));
        if (data[h-1] > data[h]) {
          if (DEBUG) printf("cucksort: shipping off [%d, %d]\n", *data, *(data + 1));
          mem_swap(data, h);
          if (DEBUG) printf("cucksort: got back [%d, %d]\n", *data, *(data + 1));
        }
    } else if ((size == 2) && (data[0] > data[1])) {
            int temp = data[0];
            data[0] = data[1];
            data[1] = temp;
    }
  
    if (DEBUG) {
      printf("after a run: ");
      print_array(data,size); puts("\n");
    }
}

void little_meme(void) {
  int x[] = {1,2,3,4,5};  
  int big_meme = 3[x];
  
  printf("WHAT ARE WE DOING = %dU\n", big_meme);
  printf(":3c\n");
}

void shitLord(int to) { //>2015 //>camelCase
  for (int i; i <= to; i++) {
    if (!(i % 3)) printf("shit");
    if (!(i % 5)) printf("lord");
    if ((i % 3) && (i % 5)) printf("%d", i);

    putchar('\n');
  }
}

void current_time(void) {
  char *shit;
  time_t c = time(NULL);
  
  shit = ctime(&c);
  printf("%s\n", shit);
}

int check_benis_lenght(void) { 
    srand(time(NULL));
    int lenght = rand() % 100;
    lenght-=50;
    printf("\n/tech/'s dick is %d cm = ", lenght);
    if (lenght > 30){
      printf ("lol big benis :DDDD\n");
    }
    else if (lenght >= 20 && lenght <= 30){
      printf ("Lol normal benis\n");
    }
    else if (lenght <= 0 && lenght >= -10) {
      printf("Bagina\n");
    }
    else if (lenght > 0 && lenght < 20) {
      printf ("Small benis DDDDDDD:\n");
    }
    else {
      printf ("Deep bagina lol ::DDDDDDD\n");
    }
  
    printf("(this function has been written by a small dicked cuck that likes small penis reaction femdom videos)\n\n");
      
    return(lenght);
}